package eco2automotive.util;
/**  
 *  First-In First-Out structure
  * @version 1.0
  * @autor Fco. Javier Sánchez Esparza
  */ 
public class Fifo {
    private Node first = null;
    private Node last = null;
    private int leng=0;
    
    private static class Node {
            Object object;
            Node next;
    }   
    /**
     * Adds a Object to the structure
     * @param obj
     */
    public void add(Object obj){
            Node aux=new Node();
            aux.object=obj;
            if(leng==0){
                    first=aux;
            }else{
                    last.next=aux;
            }
            last=aux;
            leng++;
        }
    /**
     * Extract a element
     * @return
     */
    public Object extract(){
            Object obj=new Object();
            if(leng==0){return null;}
            obj=first.object;
            first=first.next;
            leng--;
            return obj;
    }   
    /**
     * Return the lenght
     * @return
     */
    public int getLength(){
            return leng;
    }
}

